// components/feed-card/feed-card.js
import CommunityModule from '../../models/3.0/community'

Component({
  /**
   * Component properties
   */
  options: {
    addGlobalClass: true
  },
  properties: {
    collectionNumber:{
      type: String
    },
    isCollected:{
      type: Boolean,
    },
    type:{
      type: String
    },
    _id: {
      type: String
    },
    isPraise: {
      type: Boolean
    },
    avatar: {
      type: String
    },
    nickName: {
      type: String
    },
    topic: {
      type: Array
    },
    position:{
      type: String
    },
    date: {
      type: String
    },
    content: {
      type: String
    },
    coverUrl:{
      type: String
    },
    collectionNumber: {
      type: String
    },
    commentNumber: {
      type: String
    },
    transpondNumber: {
      type: String
    },
    praiseNumber: {
      type: String
    },
    expand: {
      type: Boolean,
      value: false
    },
    userId:{
      type: String
    },
    ownUserId: {
      type: String
    },
    images:{
      type: Array
    },
    boolean:{
      type:Boolean
    }
  
  },

  /**
   * Component initial data
   */
  data: {
    show: false,
     user:{
      nickName:'',
      avatar:'',
      userId:''
     }
  },

  /**
   * Component methods
   */
  methods: {
    del(){
      if(!wx.getStorageSync('userInfo').user_id ){
        return
      }
      CommunityModule.dellent({
         id:this.data._id
      }).then(res=>{
        wx.showToast({
          title: '删除成功'
        })
        this.triggerEvent('parent')
        this.setData({ show: false });
      })
    },
    // 关注
    attention(){
      CommunityModule.guanzhu({
        fansUserId:this.data.userId,
        userId:wx.getStorageSync('userInfo').user_id || 0,
      })
    },
    // 添加
    report(){
      CommunityModule.follow({
        userId:wx.getStorageSync('userInfo').user_id || 0,
        type: 0,
        id:this._data._id
      })
      this.setData({ show: false  });
    },
    // 展开
    onExpand() {
      this.setData({
        expand: false
      })
    },
    // 显示隐藏页面
    button(){    
      this.setData({
        show: true 
      });
    },
    onClose(){
      this.setData({ show: false });
      this.triggerEvent('parent')
    },

    like() {
      if(this.data.isPraise===false){
      CommunityModule.momentLike({
        id: this.data._id,
        type: 0
      }).then(res=>{
        this.setData({
          isPraise:true,
          praiseNumber:+(this.data.praiseNumber)+1
        })
      })
    } else{
      CommunityModule.noMomentLike({
        id: this.data._id,
        type: 0
      }).then(res=>{
        this.setData({
          isPraise:false,
          praiseNumber:+(this.data.praiseNumber)-1
        })
      })
    } 
    }
  }
})
